package com.personnel_management.controller;

import com.personnel_management.service.StaffService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class LoginController {
    @Autowired
    StaffService staffService;
    @RequestMapping("/")
    public String index()
    {
        return "redirect:login.html";
    }
    /*@CrossOrigin("*")
    @RequestMapping("login")
    @ResponseBody
    public boolean login(String user,String pass)
    {
        return user.equals("admin") && pass.equals("admin");
    }*/

    //新的登录接口，返回值0代表失败，1代表管理员，2代表普通用户
    @CrossOrigin("*")
    @RequestMapping("login")
    @ResponseBody
    public Integer login(String user,String pass)
    {
        if(user.equals("admin") && pass.equals("admin")) return 1;
        else if(user.equals(pass)&& staffService.findStaff(user)) return 2;
        else return 0;
    }

}
